package com.hqyj.ssm_project.service;

import com.hqyj.ssm_project.mapper.DetpMapper;
import com.hqyj.ssm_project.pojo.Detp;
import com.hqyj.ssm_project.utils.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Service
public class DetpServiceImp implements DetpService {
    @Autowired
    private DetpMapper detpMapper;

    @Override
    public int deleteByPrimaryKey(Integer detpId) {
        return detpMapper.deleteByPrimaryKey(detpId);
    }

    @Override
    public int insert(Detp row) {
        return detpMapper.insert(row);
    }

    @Override
    public int insertSelective(Detp row) {
        return detpMapper.insertSelective(row);
    }

    @Override
    public Detp selectByPrimaryKey(Integer detpId) {
        return detpMapper.selectByPrimaryKey(detpId);
    }

    @Override
    public int updateByPrimaryKeySelective(Detp row) {
        return detpMapper.updateByPrimaryKeySelective(row);
    }

    @Override
    public int updateByPrimaryKey(Detp row) {
        return detpMapper.updateByPrimaryKey(row);
    }

    @Override
    public List<Detp> selectDetp() {
        return detpMapper.selectDetp();
    }

    @Override
    public void insertDetp(Detp detp) {
        detpMapper.insertDetp(detp);
    }

    @Override
    public PageUtil<Detp> selectDetpLimit(Integer currentNum) {
        PageUtil<Detp> detpPageUtil = this.detpMapper.selectCount();
        HashMap<String, Object> map = new HashMap<>();
        map.put("startindex", (currentNum - 1) * detpPageUtil.getPageUnit());
        map.put("pageunit", detpPageUtil.getPageUnit());
        List<Detp> userList = this.detpMapper.selectDetpByPageNum(map);
        detpPageUtil.setDataList(userList);
        detpPageUtil.setCurrentNum(currentNum);
        return detpPageUtil;
    }
}
